package dev.ideas.funkyj.sequence;

import dev.ideas.funkyj.tuple.Pair;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static dev.ideas.funkyj.sequence.Sequence.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 */
public class FromWhereTo {

    @Test
    public void fromWhereTo() {
        final Sequence<String> seq = from(1, 2, 3, 4).where(even).to(string);

        assertEquals(seq.asList(), Arrays.asList("2", "4"));
        assertEquals(seq.first(), "2");
        assertEquals("second asList should result as the first", seq.asList(), Arrays.asList("2", "4")); //todo
    }

    @Test public void compose() {
        assertEquals(from(range(1, 4)).where(even.and(in(3, 4))).asList(), Arrays.asList(4));
    }

    @Test public void emptySourceIterationIsOk() {
        assertTrue(from().asList().isEmpty());
    }


    @Test
    public void seq2() {
        final List<Pair<Integer,Character>> l1 =
                from(from(1, 2, 3), from('a', 'b', 'c'))
                .where1(even)
                .asList();

        System.out.println("l1 = " + l1);

        final List<Pair<Integer,Character>> l2 =
                from(1, 2, 3).zip('a', 'b', 'c')
                .where1(even.not())
                .where2(equal('a').or(equal('c')))
                .asList();

        System.out.println("l2 = " + l2);

        final List<Pair<Integer,Character>> l3 =
                from(1, 2, 3).zip('a', 'b', 'c')
                .where(even.with(equal('b')))
                .asList();

        System.out.println("l3 = " + l3);
    }

    @Test
    public void seq3() {
        final Sequence3<Integer,Character,Boolean> seq =
                from(from(1, 2, 3), from('a', 'b', 'c'), from(true, false, true));

        System.out.println(seq.where1(even).asList());
        System.out.println(seq.where2(equal('b')).asList());
        System.out.println(seq.where3(isTrue).asList());
    }
}
